<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>新增字典信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/layui/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="width:100%;" id="dataFrm">

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">选择等级</label>
        <div class="layui-input-block lev">
            <input type="radio" name="lev" value="1" title="1级" checked>
            <input type="radio" name="lev" value="2" title="2级">
            <input type="radio" name="lev" value="3" title="3级">
        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">上级菜单:</label>
        <div class="layui-input-block" style="width:150px">
            <select id="dics" name="allLev" class="select" lay-filter="dics" lay-search>
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">字典文本:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input name" name="name" lay-verify="required" placeholder="请输入名称">
        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">是否启用</label>
        <div class="layui-input-block isDisable">
            <input type="radio" name="isDisable" value="1" title="启用" checked>
            <input type="radio" name="isDisable" value="0" title="禁用">
        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="addDic">保存</button>
            <button id="esc" type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>
        </div>
    </div>

</form>
<script type="text/javascript" src="resources/layui/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl','upload'],function() {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //取消
        $("#esc").click(function () {
            var index1=parent.layer.getFrameIndex(window.name)
            parent.layer.close(index1);
        });

        //请求获取数据
        //动态绑定下拉菜单的数据
        var html;
        $.ajax({
            url:'/dics/list.do',
            success:function (data) {
                html += "<option value=''>-----请选择-----</option>"
                for (i = 0; i < data.length; i++) {
                    html += ("<option value='" + data[i].id + "'>" + data[i].name + "</option>")
                }
                $("#dics").append(html);
                form.render('select');
            }
        });

        form.on("submit(addDic)",function (data) {
            var index = top.layer.msg('数据保存中，请稍候',{icon: 16,time:false,shade:0.8});
            //实际使用时的提交数据
            var params=$("#dataFrm").serialize();
            console.log(params);
            $.post("dictionarys.do",params,function (res) {
                console.log(res.code);
                if(res.code==4009){
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    var index1=parent.layer.getFrameIndex(window.name)
                    parent.layer.close(index1);
                    parent.location.reload();
                }else if(res.code=-4008){
                    layer.msg(res.msg);
                }else if(res.code=-4009){
                    layer.msg(res.msg);
                }
            },"json");
            return false;
        });
    })
</script>
</body>
</html>